package com.wps.wdztv6.api.forest.oaself;

import cn.hutool.core.util.StrUtil;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.wps.wdztv6.config.AppServersProperties;
import lombok.ToString;
import org.springframework.context.annotation.Configuration;

import java.net.URI;

@Configuration
public class OASelfInfo {

    @ToString
    public static class ResKeys {
        public static final String CODE = "code";
        public static final String DATA = "data";
    }

    @ToString
    public static class ResState {
        /**
         * {"code":"9999","url":"/"}
         * <p>
         * {"code":"000000","mesg":"处理成功","timestamp":"2023-09-26T09:26:35.475Z","data":{"dept":
         */
        public static final String SUCCESS_CODE = "000000";
        public static final String FAILED_CODE = "9999";
    }


    @ToString
    public static class OASelfAddressSource implements AddressSource {

        @Override
        public ForestAddress getAddress(ForestRequest forestRequest) {
            String oaselfServerUrl = AppServersProperties.oaselfServerUrl;
            URI uri = URI.create(oaselfServerUrl);
            int port = uri.getPort();
            String host = uri.getHost();
            String scheme = uri.getScheme();
            String path = uri.getPath();

            if (StrUtil.isBlank(path)) {
                return new ForestAddress(scheme, host, port);
            }
            return new ForestAddress(scheme, host, port, path);
        }

       /* public static void main(String[] args) {
            URI uri = URI.create("http://124.17.100.194:30012");
            int port = uri.getPort();
            String host = uri.getHost();
            String scheme = uri.getScheme();
            String path = uri.getPath();
            ForestAddress forestAddress = new ForestAddress(scheme, host, port, path);
            System.out.println(forestAddress);
        }*/
    }

}
